/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.io.*;
import java.util.*;
import java.sql.*;

public class LoginFormBean {

    public String custid;
    public String password;
    public String firstname;
    public String defaultacc;

    public Hashtable errors;
    public DbConnect dbc;

    public boolean validate() {
        boolean bool = true;
        if (custid.equals("")) {
            errors.put("customer", "Please Enter Your Customer Id");
            custid = "";
            bool = false;
        }
        if (password.equals("")) {
            errors.put("pass", "Please Enter Your Password");
            password = "";
            bool = false;
        }
        return bool;
    }

    public String getErrorMsg(String s) {
        String errorMsg = (String) errors.get(s.trim());
        return (errorMsg == null) ? "" : errorMsg;
    }

    public LoginFormBean() {
        custid = "";
        password = "";
        errors = new Hashtable();
    }

    public String getUsr() {
        return custid;
    }

    public String getPwd() {
        return password;
    }

    public void setUsr(String fname) {
        custid = fname;
    }

    public void setPwd(String lname) {
        password = lname;
    }
    public void setFirstname(String l){
       firstname=l;
    }
     public void setDefaultacc(String b){
       defaultacc=b;
    }

    public boolean match() {

        boolean flag = false;
        Connection con = null;
dbc=new DbConnect();

        
            try {
         
                con = dbc.getOracleConnection();
                Statement st = con.createStatement();
                ResultSet res = st.executeQuery("select firstname,custid,password from onbill_customer where custid="+"'"+custid+"'"+"and password="+"'"+password+"'");
                if(res.next()){
                     flag = true;
                     setFirstname(res.getString(1));
                }
                 else {
                    errors.put("database","Login Failed Please Try Again");
                }
                ResultSet res1=st.executeQuery("select accno from onbill_account where custid="+custid+"and defstatus=1");
                res1.next();
                setDefaultacc(res1.getString(1));
                
               


            
        } catch (Exception e) {
            e.printStackTrace();
        }

        return flag;
    }
}